package GUI;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

import GUI.manager.VentanaFactory;
import GUI.manager.VentanaManager;
import core.model.Carrito;
import core.model.Lista;

public class panelModificarLista extends javax.swing.JPanel implements
ActionListener, MouseListener {

    
    /**
	 * 
	 */
	private static final long serialVersionUID = -6914693780113848167L;

	
	
	public String[][] convertirArray(List<Carrito> listas)
	{
		String [][] datos=new String [listas.size()][4];
		for(int i=0;i<listas.size();i++)
		{
			datos[i][0]=String.valueOf(listas.get(i).getNombre_producto());
			datos[i][1]=String.valueOf(listas.get(i).getCantidad());
			//datos[i][]=String.valueOf(listas.get(i).getUnidad());
			datos[i][2]=String.valueOf(listas.get(i).getPrecio());
			datos[i][3]=String.valueOf(listas.get(i).getNombre_empresa());


			
		}
		return datos;
	}
	
	public panelModificarLista() {
        initComponents();
    }

                            
    private void initComponents() {

        panelCentro = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        bEliminar = new javax.swing.JButton();
        bGuardar = new javax.swing.JButton();
        bAgregar = new javax.swing.JButton();
        bAtras = new javax.swing.JButton();
        bTitulo = new javax.swing.JButton();
        etiquetaNick = new javax.swing.JLabel();
        botonSalir = new javax.swing.JButton();
        etiquetaEntrada = new javax.swing.JLabel();
        bCrearLista = new javax.swing.JButton();
        bOpciones = new javax.swing.JButton();
        bSugerencias = new javax.swing.JButton();
        bHistorial = new javax.swing.JButton();
        bAyuda = new javax.swing.JButton();
        bBusqueda = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));

        panelCentro.setBackground(new java.awt.Color(255, 255, 255));

        jTable1.setModel(modelo);
		jScrollPane1.setViewportView(jTable1);

        bEliminar.setBackground(new java.awt.Color(255, 255, 255));
        bEliminar.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
        bEliminar.setForeground(new java.awt.Color(243, 15, 120));
        bEliminar.setIcon(new javax.swing.ImageIcon("src/GUI/resources/botonEliminar.png")); // NOI18N
        bEliminar.setBorder(null);
        bEliminar.addActionListener(this);
       

        bGuardar.setBackground(new java.awt.Color(255, 255, 255));
        bGuardar.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
        bGuardar.setForeground(new java.awt.Color(243, 15, 120));
        bGuardar.setIcon(new javax.swing.ImageIcon("src/GUI/resources/botonGuardar.png")); // NOI18N
        bGuardar.setBorder(null);
        bGuardar.addActionListener(this);
      

        bAgregar.setBackground(new java.awt.Color(255, 255, 255));
        bAgregar.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
        bAgregar.setForeground(new java.awt.Color(243, 15, 120));
        bAgregar.setIcon(new javax.swing.ImageIcon("src/GUI/resources/botonAgregar.png")); // NOI18N
        bAgregar.setBorder(null);
        bAgregar.addActionListener(this);
       

        bAtras.setBackground(new java.awt.Color(255, 255, 255));
        bAtras.setIcon(new javax.swing.ImageIcon("src/GUI/resources/boton_atras.png")); // NOI18N
        bAtras.setBorder(null);
        bAtras.addActionListener(this);
      

        javax.swing.GroupLayout panelCentroLayout = new javax.swing.GroupLayout(panelCentro);
        panelCentro.setLayout(panelCentroLayout);
        panelCentroLayout.setHorizontalGroup(
            panelCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCentroLayout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(panelCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelCentroLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(bAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                        .addComponent(bEliminar)
                        .addGap(40, 40, 40)
                        .addComponent(bGuardar)
                        .addGap(109, 109, 109))
                    .addGroup(panelCentroLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 483, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
            .addGroup(panelCentroLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bAtras)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        panelCentroLayout.setVerticalGroup(
            panelCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCentroLayout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(panelCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelCentroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(bEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(bGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(bAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addComponent(bAtras)
                .addContainerGap())
        );

        bTitulo.setIcon(new javax.swing.ImageIcon("src/GUI/resources/encabezadoMain.png")); // NOI18N
        bTitulo.setBorder(null);
        bTitulo.setBorderPainted(false);
        bTitulo.addActionListener(this);
        bTitulo.setBackground(new java.awt.Color(255, 255, 255));

        etiquetaNick.setBackground(new java.awt.Color(255, 255, 255));
        etiquetaNick.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
        etiquetaNick.setText(panelPrincipal.nick);
        etiquetaNick.setToolTipText("");

        botonSalir.setIcon(new javax.swing.ImageIcon("src/GUI/resources/menu-salir.png")); // NOI18N
        botonSalir.setBorderPainted(false);
        botonSalir.setBackground(new java.awt.Color(255, 255, 255));
        botonSalir.addActionListener(this);

        etiquetaEntrada.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
        etiquetaEntrada.setForeground(new java.awt.Color(243, 15, 120));
        etiquetaEntrada.setText("BIENVENIDO A LISTA DE LA COMPRA MAKER ");

        bCrearLista.setBackground(new java.awt.Color(255, 255, 255));
        bCrearLista.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
        bCrearLista.setIcon(new javax.swing.ImageIcon("src/GUI/resources/botonCrearLista.png")); // NOI18N
        bCrearLista.setBorderPainted(false);
        bCrearLista.addActionListener(this);

        bOpciones.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
        bOpciones.setIcon(new javax.swing.ImageIcon("src/GUI/resources/botonOpciones.png")); // NOI18N
        bOpciones.setBorderPainted(false);
        bOpciones.setBackground(new java.awt.Color(255, 255, 255));
        bOpciones.addActionListener(this);

        bSugerencias.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
        bSugerencias.setIcon(new javax.swing.ImageIcon("src/GUI/resources/botonSugerencias.png")); // NOI18N
        bSugerencias.setBorderPainted(false);
        bSugerencias.setBackground(new java.awt.Color(255, 255, 255));
        bSugerencias.addActionListener(this);

        bHistorial.setBackground(new java.awt.Color(255, 255, 255));
        bHistorial.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
        bHistorial.setIcon(new javax.swing.ImageIcon("src/GUI/resources/botonHistorial.png")); // NOI18N
        bHistorial.setBorderPainted(false);
        bHistorial.addActionListener(this);

        bAyuda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
        bAyuda.setIcon(new javax.swing.ImageIcon("src/GUI/resources/botonAyuda.png")); // NOI18N
        bAyuda.setBorderPainted(false);
        bAyuda.setBackground(new java.awt.Color(255, 255, 255));
        bAyuda.addActionListener(this);

        bBusqueda.setBackground(new java.awt.Color(0, 102, 0));
        bBusqueda.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
        bBusqueda.setIcon(new javax.swing.ImageIcon("src/GUI/resources/botonBusqueda.png")); // NOI18N
        bBusqueda.setToolTipText("");
        bBusqueda.setBorderPainted(false);
        bBusqueda.addActionListener(this);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(bCrearLista, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(bBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(bHistorial, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(bSugerencias, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(bOpciones, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(bAyuda, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(26, 26, 26)
                        .addComponent(panelCentro, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(9, 9, 9))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(96, 96, 96)
                        .addComponent(bTitulo)
                        .addGap(44, 44, 44)
                        .addComponent(botonSalir))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(84, 84, 84)
                        .addComponent(etiquetaEntrada)
                        .addGap(46, 46, 46)
                        .addComponent(etiquetaNick, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonSalir))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(etiquetaEntrada)
                    .addComponent(etiquetaNick))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(bCrearLista, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(bHistorial, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(bSugerencias, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(bOpciones, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(bAyuda, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(panelCentro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }
                      
    private javax.swing.JButton bAgregar;
    private javax.swing.JButton bAtras;
   
    private javax.swing.JButton bAyuda;
    private javax.swing.JButton bBusqueda;
    private javax.swing.JButton bCrearLista;
    private javax.swing.JButton bEliminar;
    private javax.swing.JButton bGuardar;
    private javax.swing.JButton bHistorial;
    private javax.swing.JButton bOpciones;
    private javax.swing.JButton bSugerencias;
    private javax.swing.JButton bTitulo;
    private javax.swing.JButton botonSalir;
    private javax.swing.JLabel etiquetaEntrada;
    private javax.swing.JLabel etiquetaNick;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JPanel panelCentro;
    private JFrame actual;
	private JPanel estePanel = this;

	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == bSugerencias) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSugerencias());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}

		if (e.getSource() == bBusqueda) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelBusqueda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}

		if (e.getSource() == bHistorial) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelHistorial());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bOpciones) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelOpciones());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bAyuda) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelAyuda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		
		if (e.getSource() == botonSalir) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSalir(30));
			actual.setPreferredSize(new Dimension(610, 330));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bAtras) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelHistorial());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bAgregar) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelCrearListaBusqueda());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}

	}
	
	
	Point punto=new Point();
	List<Carrito> carritos;

	int codigo = panelHistorial.codigo_lista;
	VentanaManager ventanaManager=VentanaFactory.getInstance();

	List<Carrito> listas=ventanaManager.findByLista(codigo);
	DefaultTableModel modelo=new DefaultTableModel(convertirArray(listas), new Object[]{"Nombre producto","Cantidad","Precio","Nombre supermercado"});



	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		punto = e.getPoint();
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
                     
}
